<template>
  <div class="header-nav">
    <div class="header-nav-left">
      <div class="color-black">
        <span class="iconfont icon-dingwei"></span>宁波
      </div>
      <a href="#" class="switch-city">切换城市</a>
      <div>
        [
        <span class="city">奉化</span>
        <span class="city">余姚</span>
        <span class="city">慈溪</span>
        ]
      </div>
      <div class="login-box">
        <router-link class="hover-active" to="/login">立即登录</router-link>
        <router-link to="/enroll">注册</router-link>
      </div>
      <div class="login-box" v-if="false">
        <a href="#" class="hover-active">昵称</a>
        <a href="#" class="login-box-a-two">退出</a>
      </div>
    </div>
    <div class="header-nav-right">
      <div
        :class="[
          item.id == 2 ? '' : 'header-nav-list-active',
          'header-nav-list',
        ]"
        v-for="item in navList"
        :key="item.id"
        @mouseover="overHeaderNavItem"
        @mouseout="outHeaderNavItem"
      >
        <div class="moveIn_active nav-list-itemName">
          {{ item.name }}
        </div>
        <ul
          class="header-nav-item-box"
          v-if="item.id != 2 && item.id != 5"
          v-show="item.isShowChildNode"
        >
          <li
            class="header-nav-item moveIn_active"
            v-for="(childNodeItem, index) in item.childNode"
            :key="index"
          >
            {{ childNodeItem }}
          </li>
        </ul>
        <div
          class="website_nav"
          v-if="item.id == 5"
          v-show="item.isShowChildNode"
        >
          <dl class="website_nav_dl dl-one">
            <dt>酒店旅游</dt>
            <dd class="moveIn_active">国际机票</dd>
            <dd class="moveIn_active">火车票</dd>
            <dd class="moveIn_active">民宿</dd>
            <dd class="moveIn_active">经济型酒店</dd>
            <dd class="moveIn_active">主题酒店</dd>
            <dd class="moveIn_active">商务酒店</dd>
            <dd class="moveIn_active">公寓</dd>
            <dd class="moveIn_active">豪华酒店</dd>
            <dd class="moveIn_active">客栈</dd>
            <dd class="moveIn_active">青年旅社</dd>
            <dd class="moveIn_active">度假酒店</dd>
            <dd class="moveIn_active">别墅</dd>
            <dd class="moveIn_active">农家院</dd>
          </dl>
          <dl class="website_nav_dl dl-two">
            <dt>吃美食</dt>
            <dd class="moveIn_active">烤鱼</dd>
            <dd class="moveIn_active">特色小吃</dd>
            <dd class="moveIn_active">自助餐</dd>
            <dd class="moveIn_active">代金券</dd>
          </dl>
          <dl class="website_nav_dl dl-three">
            <dt>看电影</dt>
            <dd class="moveIn_active">热门电影</dd>
            <dd class="moveIn_active">热门影院</dd>
            <dd class="moveIn_active">热门电影口碑榜</dd>
            <dd class="moveIn_active">最受期待电影</dd>
            <dd class="moveIn_active">国内票房榜</dd>
            <dd class="moveIn_active">北美票房榜</dd>
            <dd class="moveIn_active">电影排行榜</dd>
          </dl>
          <dl class="dl-four">
            <dt>手机应用</dt>
            <dd>
              <!-- <img src="/src/components/headNav/images/meituan.png" /> -->
              <img src="/src/components/header/images/meituan.png" />
            </dd>
            <dd><img src="/src/components/header/images/waimai.png" /></dd>
            <dd><img src="/src/components/header/images/download.png" /></dd>
            <dd><img src="/src/components/header/images/dianping.png" /></dd>
            <dd><img src="/src/components/header/images/maoyan.png" /></dd>
          </dl>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Header",
};
</script>
<script setup>
import { ref } from "vue";

const navList = ref([
  {
    id: 1,
    name: "我的美团",
    isShowChildNode: false,
    childNode: ["我的订单", "我的收藏", "抵用券", "账号设置"],
  },
  {
    id: 2,
    name: "手机app",
    isShowChildNode: false,
  },
  {
    id: 3,
    name: "商家中心",
    isShowChildNode: false,
    childNode: [
      "美团餐饮商户中心",
      "登录商家中心",
      "美团智能收银",
      "我想合作",
      "手机免费开店",
      "到店综合业务招募",
      "餐饮合作商招募",
      "商家申请开票",
      "免费合作美团排队",
    ],
  },
  {
    id: 4,
    name: "美团规则",
    isShowChildNode: false,
    childNode: ["规则中心", "规则目录", "规则评议院"],
  },
  {
    id: 5,
    name: "网站导航",
    isShowChildNode: false,
  },
]);

// 移入头部导航
const overHeaderNavItem = (e) => {
  // console.log(e.currentTarget.childNodes); // 所有子节点
  // console.log(e.currentTarget.firstChild.innerHTML); //第一个子节点文本
  const text = e.currentTarget.firstChild.innerHTML;
  const index = navList.value.findIndex((item) => item.name == text);
  navList.value[index].isShowChildNode = true;
  if (text !== "手机app")
    e.currentTarget.firstChild.classList.add("nav-list-itemName-active");
};

// 移出头部导航
const outHeaderNavItem = (e) => {
  const index = navList.value.findIndex(
    (item) => item.name == e.currentTarget.firstChild.innerHTML
  );
  navList.value[index].isShowChildNode = false;
  e.currentTarget.firstChild.classList.remove("nav-list-itemName-active");
};
</script>

<style scoped>
.hover-active {
  color: #fe8c00;
}
.header-nav {
  width: 1190px;
  height: 40px;
  font-size: 12px;
  color: #999999;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
}
.header-nav-left {
  display: flex;
  align-items: center;
}
.color-black {
  color: #666666;
}
.switch-city {
  margin: 0 4px;
  padding: 0 2px;
  color: #666666;
  background-color: #f4f4f4;
  border: 1px solid #e5e5e5;
}
.switch-city:hover {
  color: #fe8c00;
}
.header-nav-left .city {
  margin: 0 4px;
}
.header-nav-left .city:hover {
  color: #fe8c00;
}
.header-nav-left .login-box {
  margin-left: 15px;
}
.header-nav-left .login-box a {
  margin-left: 10px;
}
.login-box-a-two:hover {
  color: #fe8c00;
}

/* 头部导航右边 */
.header-nav-right {
  display: flex;
  z-index: 3;
}
.header-nav-list {
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0);
  z-index: 2;
}
.header-nav-list-active:hover {
  border: 1px solid #e5e5e5;
  box-shadow: 0 3px 5px 0 rgb(0 0 0 / 10%);
  border-bottom: #fff;
  background-color: #fff;
  color: #fe8c00;
}
.nav-list-itemName {
  position: relative;
  width: 78px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  z-index: 2;
}
.nav-list-itemName-active {
  background-color: #fff;
}
.moveIn_active:hover {
  color: #fe8c00;
}
.header-nav-item-box {
  border: 1px solid #e5e5e5;
  box-shadow: 0 3px 5px 0 rgb(0 0 0 / 10%);
  background-color: #fff;
  color: #999999;
  position: absolute;
  /* width: 100%; */
  /* padding: 0 10px; */
  right: -1px;
  top: 38px;
  z-index: 1;
}
.header-nav-item {
  height: 40px;
  min-width: 78px;
  padding: 0 9px;
  box-sizing: border-box;
  white-space: nowrap;
  text-align: center;
  line-height: 40px;
}

/* 网站导航 */
.website_nav {
  width: 1190px;
  border: 1px solid #e5e5e5;
  box-shadow: 0 3px 5px 0 rgb(0 0 0 / 10%);
  padding: 30px 36px 36px 47px;
  box-sizing: border-box;
  background-color: #fff;
  color: #999999;
  position: absolute;
  display: flex;
  justify-content: space-between;
  top: 38px;
  right: -1px;
  z-index: 99;
}
.dl-one {
  width: 234px;
}
.dl-one dd {
  width: 30%;
}
.dl-two {
  width: 156px;
}
.dl-two dd {
  width: 50%;
}
.dl-three {
  width: 90px;
}
.dl-three dd {
  width: 100%;
}
.dl-four {
  width: 380px;
  float: right;
}

.dl-four dt {
  width: 380px;
  margin-bottom: 26px;
  text-align: center;
  font-size: 14px;
  color: #222222;
  font-weight: 500;
}

.dl-four dd {
  display: inline-block;
  width: 60px;
  height: 60px;
  margin: 0 8px;
}
.dl-four dd img {
  width: 60px;
  height: 60px;
}
.website_nav_dl {
  padding-right: 40px;
}
.website_nav_dl dt {
  margin-bottom: 26px;
  text-align: center;
  font-size: 14px;
  color: #222222;
  font-weight: 500;
}
.website_nav_dl dd {
  padding: 5px 0;
  height: 16px;
  line-height: 16px;
  display: inline-block;
  text-align: center;
}
</style>
